﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LambdaExtention
{
    class Test
    {
        static void Main(string[] args)
        {
            StringBuilder testBuilder = new StringBuilder();
            testBuilder.Append("1234567891011121314151617181920");
            StringBuilder result = testBuilder.Substring(5, 15);
            Console.WriteLine(result);
            Student[] students = new Student[] { new Student("Stoqn", "Petrov",20), new Student("Asen", "Petrov",15), 
                new Student("Petur", "Petrov",58), new Student("Petur", "Asenov",24), new Student("Boris", "Petrov",18) };

            var results =
                from student in students
                where student.LastName.CompareTo(student.FirstName) < 0
                select student;
            
            foreach (var item in results)
            {
                Console.WriteLine(item.FirstName + " " + item.LastName);
            }

            var resultAge =
               from student in students
               where student.Age>=18&&student.Age>=24
               select student.FirstName + " " +student.LastName;

            foreach (var item in resultAge)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine();
            //var sorted = students.OrderBy(st => st.FirstName).ThenBy(st => st.LastName);
            //foreach (var item in sorted)
            //{
            //    Console.WriteLine(item.FirstName+" "+item.LastName);
            //}

            var sortedStudents =
                from student in students
                orderby student.FirstName descending, student.LastName descending
                select student;
            foreach (var item in sortedStudents)
            {
                Console.WriteLine(item.FirstName + " " + item.LastName);
            }


            Console.WriteLine();
            int[] numbers = new int[] {21,42,4,8,7 };
            //var numbersDevided = numbers.Where(number => number % 3 == 0 && number % 7 == 0);

            var numbersDevided =
                from number in numbers
                where number % 3 == 0 && number % 7 == 0
                select number;

            foreach (var item in numbersDevided)
            {
                Console.WriteLine(item);
            }
        }
    }
}
